<style>
.affix{top:10px;}
.head-style-list li,.editor-template-list li{cursor: pointer;}
</style>

		<div class="ui-portlet">
			{{template wxes/_user_wxes}}
			<ol class="breadcrumb">
			  <li><a href="/users/index"><i class="fa fa-home"></i>&nbsp;&nbsp;{{__('Personal Center')}}</a></li>
			  <li class="active">编辑图文消息</li>
			</ol>
		</div>           
       <hr>

{{$this->Form->create('WxMsg',array('class'=>'form-horizontal','role'=>'form'))}}
	<div class="form-group">
		<label class="col-sm-2 control-label" for="WxMsgName">消息标题</label>
		<div class="col-sm-9 controls">
			{{$this->Form->hidden('id')}}
			{{$this->Form->input('name',array('class'=>'form-control','require'=>'require','div'=>false,'label'=>false))}}
		</div>
	</div>
	<div class="form-group" id="divWxMsgWordEvent">
			<label class="col-sm-2 control-label" for="WxMsgWordEvent">自动回复关键字</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('word_event',array('class'=>'form-control','required'=>'required','div'=>false,'label'=>false,'after'=>'多个关键字使用分号隔开'))}}
			</div>
	</div>
	{{if $_REQUEST['type']=='text'}}
	
		{{$this->Form->hidden('status',array('value'=>'2'))}}
		{{$this->Form->hidden('msg_type',array('value'=>'text'))}}
		
		<div class="form-group" id="divWxMsgSummary">
			<label class="col-sm-2 control-label" for="WxMsgSummary">回复文本</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('summary',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3','after'=>'<p>单图文消息时作为消息摘要发出；文本消息时作为消息内容发出</p>'))}}
			</div>
		</div>
	{{elseif $_REQUEST['type']=='media_id'}}
	
		{{$this->Form->hidden('status',array('value'=>'2'))}}
		{{$this->Form->hidden('msg_type',array('value'=>'media_id'))}}
		
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgCoverimg">封面图片</label>
			<div class="col-sm-9 controls select">
				{{$this->Swfupload->load('coverimg',array(
				'label'=>false,'modelClass'=>'WxMsg',
				'upload_limit'=>1,'isadmin' => false,
				'file_types'=> '*.jpg;*.gif;*.png;*.bmp',
				'isadmin'=>false
				))}}
			</div>
		</div>
	{{elseif $_REQUEST['type']=='link'}}
	
		{{$this->Form->hidden('status',array('value'=>'2'))}}
		{{$this->Form->hidden('msg_type',array('value'=>'link'))}}
		
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgPriority">消息优先级</label>
			<div class="col-sm-9 controls select">
				{{$this->Form->input('priority',array('class'=>'form-control','div'=>false,'label'=>false,))}}
				<p>在用户发送消息查询时被命中的消息，按优先级从大到小排列</p>
			</div>
		</div>	
		<div class="form-group" id="divWxMsgUrl">
			<label class="col-sm-2 control-label" for="WxMsgUrl">打开网址</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('url',array('class'=>'form-control','div'=>false,'label'=>false,'after'=>'<p>打开指定的网址，留空时打开消息正文地址</p>'))}}
			</div>
		</div>
	{{else}}
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgCateId">消息所属分类</label>
			<div class="col-sm-9 controls select">
				{{$this->Form->input('cate_id',array('class'=>'form-control','div'=>false,'label'=>false))}}
				<p><a href="{{$this->Html->url(array('controller'=>'user_cates','action'=>'add','WxMsg'))}}">新增回复消息分类</a></p>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgCoverimg">封面图片</label>
			<div class="col-sm-9 controls select">
				{{$this->Swfupload->load('coverimg',array(
				'label'=>false,'modelClass'=>'WxMsg',
				'upload_limit'=>1,'isadmin' => false,
				'file_types'=> '*.jpg;*.gif;*.png;*.bmp',
				'isadmin'=>false
				))}}
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgMsgType">菜单类型</label>
			<div class="col-sm-9 controls select">
				{{$this->Form->input('msg_type',array('class'=>'form-control','div'=>false,'label'=>false,'options'=>array('link'=>'图文消息','text'=>'文本消息',)))}}
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label" for="WxMsgPriority">消息优先级</label>
			<div class="col-sm-9 controls select">
				{{$this->Form->input('priority',array('class'=>'form-control','div'=>false,'label'=>false,))}}
				<p>在用户发送消息查询时被命中的消息，按优先级从大到小排列</p>
			</div>
		</div>
		<div class="form-group" id="divWxMsgWordEvent">
			<label class="col-sm-2 control-label" for="WxMsgWordEvent">交互消息</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('word_event',array('class'=>'form-control','required'=>'required','div'=>false,'label'=>false,'after'=>'用户发送过来的文本或点击菜单事件代码'))}}
			</div>
		</div>
		<div class="form-group" id="divWxMsgSummary">
			<label class="col-sm-2 control-label" for="WxMsgSummary">消息摘要</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('summary',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3','after'=>'<p>单图文消息时作为消息摘要发出；文本消息时作为消息内容发出</p>'))}}
			</div>
		</div>
		<div class="form-group" id="divWxMsgUrl">
			<label class="col-sm-2 control-label" for="WxMsgUrl">打开网址</label>
			<div class="col-sm-9 controls">
				{{$this->Form->input('url',array('class'=>'form-control','div'=>false,'label'=>false,'after'=>'<p>打开指定的网址，留空时打开消息正文地址</p>'))}}
			</div>
		</div>
	
		<div class="form-group" id="divWxMsgUrl">
			<div class="col-sm-12 controls">
				{{$this->Form->input('content',array('class'=>'form-control','div'=>false,'label'=>false,'rows'=>'3','after'=>'<p>消息正文仅在打开消息网址才能查看到。</p>'))}}
			</div>
		</div>
	{{/if}}
	
	<div class="form-group">
		<label class="col-sm-2 control-label"></label>
		<div class="col-sm-9"><input class="btn btn-primary" type="submit" value="提交"></div>
	</div>
{{$this->Form->end()}}

{{$this->Html->script(array(
	'ckeditor/ckeditor.js',
	'swfupload/swfupload.js',
	'swfupload/swfupload.queue.js',
	'swfupload/swfupload.cookies.js',
	'swfupload/fileprogress.js',
	'swfupload/handlers.js',
))}}

<script>

var current_ckeditor_instance = null;

$(function(){
	$('#left-side-affix').width($('#left-sidebar').width());

	CKEDITOR.editorConfig = function( config ){
		config.toolbar = 'FRONT';
	}
	ckeditors['WxMsgContent'] = CKEDITOR.replace( 'WxMsgContent',
		    {
		        customConfig : '{{$this->Html->url("/js/ckeditor/front-config.js")}}'
		    });
	ckeditors['WxMsgContent'].on('focus',function(e){
		current_ckeditor_instance = e.editor;
	});
	

	/*CKEDITOR.on( 'instanceReady', function( e ){
		e.editor.document.appendStyleSheet( '{{$this->Html->url("/stylevars/getcss.css")}}' );
		e.editor.document.appendStyleSheet( '{{$this->Html->url("/css/ui-customer.css")}}' );
		//e.editor.setMode( 'source' );
		e.editor.on( 'mode', function( e ){
			if(e.editor.mode == 'wysiwyg'){
				e.editor.document.appendStyleSheet( '{{$this->Html->url("/stylevars/getcss.css")}}' );
				e.editor.document.appendStyleSheet( '{{$this->Html->url("/css/ui-customer.css")}}' );
			}
		});
		//if($('.cke_top').parent('ui-dialog-content').size()<1){
		//	$('.cke_top').addClass('clearfix').affix();
		//}
	});*/


	$('.head-style-list li').click(function(){
		var styles = $(this).data('style');
		//alert(style_str)
		//var styles = jQuery.parseJSON(style_str);
		set_style('h1,h2,h3,h4,h5,h6',styles);

	});

	$('.editor-template-list li').click(function(){
		insertHtml($(this).html());
	})

});

function insertHtml(html){
	if(current_ckeditor_instance){
		var oEditor = current_ckeditor_instance;
		// Check the active editing mode.
		if (oEditor.mode == 'wysiwyg' ){
			// Insert the desired HTML.
			oEditor.insertHtml(html);
		}
		else{
			alert($.jslanguage.wysiswyg_mode );
		}
	}
	else{	
		alert($.jslanguage.select_editor);
	}	
}

function set_style(selector,styles){
	//ckeditors['WxMsgContent'].focus();
	//ckeditors['WxMsgContent'].execCommand('selectAll');

	var html = ckeditors['WxMsgContent'].getData();
	
	var obj = $('<div id="editor-content">'+html+"</div>");
	obj.find(selector).each(function(){
		$(this).css(styles);
	});
	ckeditors['WxMsgContent'].setData(obj.html());

}
</script>

